function isEmptyObject(obj) {

    for (var key in obj) {
        break;
        return false
    }
    ;
    return true
};

function getWalking(from, to) {//根据起点终点经纬度规划步行方案
    $.ajax({
        url: 'https://restapi.amap.com/v3/direction/walking',
        async: false,
        data: {
            origin: from,
            destination: to,
            key: '3d88c2ccf23c5f05bdab214b5c9550ca'//参数
        },
        type: "POST",
        success: function (re) {
            return re;
            //console.log(re);
        }
    });
}

function getBus(from, to) {//根据起点终点经纬度规划步行方案，返回一个数组，数组中每个元素代表一个对象，对象中含有路径字符串与出行方式（步行/公交）
    //restapi.amap.com/v3/direction/transit/integrated?key=您的key&origin=116.481028,39.989643&destination=116.434446,39.90816&city=北京&cityd=北京&strategy=5&nightflag=0
    //TODO:可能改，返回时间、里程等信息
    ary = new Array();
    $.ajax({
        async: false,
        url: 'https://restapi.amap.com/v3/direction/transit/integrated',
        data: {
            origin: from,
            destination: to,
            key: '3d88c2ccf23c5f05bdab214b5c9550ca',//参数
            city: '北京',
            strategy: 5,
            nightflag: 0
        },
        type: "POST",
        success: function (re) {
            console.log(re);
            var joi = re["route"]["transits"];
            //joi[0]["distance"]
            for (var j = 0; j < re["route"]["transits"][0]["segments"].length; j++) {
                //console.log(j);
                if (re["route"]["transits"][0]["segments"][j]["walking"]["steps"].length != 0) {
                    var walkString = re["route"]["transits"][0]["segments"][j]["walking"]["steps"][0]["polyline"];
                }
                for (var k = 1; k < re["route"]["transits"][0]["segments"][j]["walking"]["steps"].length; k++) {
                    walkString = walkString + ";" + re["route"]["transits"][0]["segments"][j]["walking"]["steps"][k]["polyline"];
                }
                if (re["route"]["transits"][0]["segments"][j]["bus"]["buslines"].length != 0) {
                    var busString = re["route"]["transits"][0]["segments"][j]["bus"]["buslines"][0]["polyline"];
                    var busTime = re["route"]["transits"][0]["segments"][j]["bus"]["buslines"][0]["duration"];
                    var busDis = re["route"]["transits"][0]["segments"][j]["bus"]["buslines"][0]["distance"];
                }
                for (var k = 1; k < re["route"]["transits"][0]["segments"][j]["bus"]["buslines"].length; k++) {
                    busString = busString + ";" + re["route"]["transits"][0]["segments"][j]["bus"]["buslines"][k]["polyline"];
                }
                walkString = walkString.replace(/;/g, "-");
                busString = busString.replace(/;/g, "-");
                ary.push({
                    routeString: walkString,
                    duration: re["route"]["transits"][0]["segments"][j]["walking"]["duration"],
                    distance: re["route"]["transits"][0]["segments"][j]["walking"]["distance"],
                    routeWay: 'walk'
                });
                ary.push({
                    routeString: busString,
                    duration: busTime,
                    distance: busDis,
                    routeWay: 'bus'
                });
            }

            return re;

        }
    });
    console.log(ary);
    return ary;
}

